<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        :rowKey="(record, index) => index"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: true }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <span slot="moment" slot-scope="text">{{ text | moment }}</span>
        <ellipsis slot="ellipsis" slot-scope="text" :length="30">{{ text }}</ellipsis>
        <div slot="action" slot-scope="text, record">
          <y-button type="primary" size="small" @click="handleDetail(record)">查看</y-button>
          <a-dropdown>
            <a-menu slot="overlay" @click="handleDownload($event, record)">
              <a-menu-item key="xls"> <a-icon type="file-excel" />Excel </a-menu-item>
              <a-menu-item key="doc"> <a-icon type="file-word" />Word </a-menu-item>
            </a-menu>
            <y-button type="primary" size="small">下载<a-icon type="down" /></y-button>
          </a-dropdown>
        </div>
      </s-table>
    </a-card>
    <detail :visible.sync="visibleDetail" :data.sync="detailData" />
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getDocumentAutoList } from '@/api/cityReviewAndManage'
import detail from './components/detail.vue'
import { downloadEvt } from '@/utils/util'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    detail,
  },
  data() {
    return {
      visibleDetail: false,
      detailData: {},
      queryParam: {
        UserID: 1,
        Mode: 'autodocument',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '发文类型',
          align: 'center',
          dataIndex: 'BClass',
        },
        {
          title: '发文标题',
          align: 'center',
          dataIndex: 'Name',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '发文区级',
          align: 'center',
          dataIndex: 'MainSend',
          scopedSlots: { customRender: 'ellipsis' },
        },
        {
          title: '发文(字)',
          align: 'center',
          dataIndex: 'wenzi',
        },
        {
          title: '发文(号)',
          align: 'center',
          dataIndex: 'SNumber',
        },
        {
          title: '发文时间',
          align: 'center',
          dataIndex: 'SedRecDate',
          scopedSlots: {
            customRender: 'moment',
          },
        },
        {
          title: '发文人',
          align: 'center',
          dataIndex: 'CreateUserID',
        },
        {
          title: '操作',
          align: 'center',
          width: '180px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getDocumentAutoList(requestParameters).then((res) => res)
      },
    }
  },
  methods: {
    handleDetail(record) {
      this.detailData = record
      this.visibleDetail = true
    },
    handleDownload(e, record) {
      const url = process.env.VUE_APP_API_BASE_URL + '/EFiles/Briefcase/' + record.ID + '/' + record.Theme + '.' + e.key
      downloadEvt(url, record.Theme)
    },
  },
}
</script>
<style lang="less" scoped>
.table-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
